#include <stdio.h>
#include "dclcd.h"
#include "tskcfg.h"
#include "bsp.h"
#include "parameter.h"
#include <stdlib.h>
#include "gv.h"

static void ok(void);
static void up(void);
static void keyret(void);

static void update(uint8_t keyvalue);

static volatile uint8_t focus = 0;

const static GUI_FormKeysStru gui_calzerorunend_keys = 
{
  .mute =   NULL,
  .power =  NULL,
  .keyt =   NULL,
  .set =    NULL,
  .home =   NULL,
  .menu =   NULL,
  .keyret = keyret,
  .enter =  NULL,
  .down =   up,
  .up =     up,
  .left =   NULL,
  .right =  NULL,
  .ok =     ok,
  .volinc = NULL,
  .voldec = NULL,
  .key0 =   NULL,
  .key1 =   NULL,
  .key2 =   NULL,
  .key3 =   NULL,
  .key4 =   NULL,
  .key5 =   NULL,
  .key6 =   NULL,
  .key7 =   NULL,
  .key8 =   NULL,
  .key9 =   NULL,
};

const GUI_FormStru gui_from_calzerorunend = 
{
  .load    = dc_load_calzeroend,
  .update  = update,
  .keys    = &gui_calzerorunend_keys,
  .refresh = &gui_maxdelay_refresh_time,
};

static void update(uint8_t keyvalue)
{
	dc_comp_showhide(8, 8, focus-0);
}

static void ok(void)
{
  if(focus != 0){
    gv.co.meas_ec.manual_zero_save_key = 1;
  }else{
    gv.co.meas_ec.manual_zero_stop_key = 1;
  }
}

void keyret(void)
{
  gv.co.meas_ec.manual_zero_stop_key = 1;
}

static void up(void)
{
  if(focus != 0){
    focus = 0;
  }else{
    focus = 1;
  }
}
